
#ifndef STONE_H
#define STONE_H

#include<QString>


class stone
{
public:
    stone();
    ~stone();

    enum TYPE{jiang,che,pao,bing,shi,xiang,ma};//枚举类型，棋子种类

    int _row;//棋子所在行
    int _col;//棋子所在列
    TYPE _type;//棋子名字

    int _id;//每个棋子赋予一个身份证号，因为每个棋子都不同需要区分！
    bool _dead;//棋子是否被吃
    bool _red;//棋子所属阵营，id<16的是红方


    void init(int id){
        struct{//用结构体定义也是初始化棋子基本状态
            int row,col;
            stone::TYPE type;
        }pos[16]={//根据象棋基本棋子排布初始化16个棋子位置
                     {0,0,stone::che},
                     {0,1,stone::ma},
                     {0,2,stone::xiang},
                     {0,3,stone::shi},
                     {0,4,stone::jiang},
                     {0,5,stone::shi},
                     {0,6,stone::xiang},
                     {0,7,stone::ma},
                     {0,8,stone::che},
                     {2,1,stone::pao},
                     {2,7,stone::pao},
                     {3,0,stone::bing},
                     {3,2,stone::bing},
                     {3,4,stone::bing},
                     {3,6,stone::bing},
                     {3,8,stone::bing},
                     };

        _id=id;
        _dead=false;
        _red=id<16;

        if(id<16){
            _row=pos[id].row;
            _col=pos[id].col;
            _type=pos[id].type;
        }else{
            _row=9-pos[id-16].row;
            _col=8-pos[id-16].col;
            _type=pos[id-16].type;
        }
    }


    //根据象棋类型返回名字
    //红方为帅仕炮兵相
    QString getText(){
        if(_id<16){
            switch(this->_type){
            case che:
                return "車";
            case ma:
                return "馬";
            case pao:
                return "炮";
            case bing:
                return "兵";
            case jiang:
                return "帥";
            case xiang:
                return "相";
            case shi:
                return "仕";
            }
            return "错误";
        }
        //黑方为将士砲卒象
        else if(_id>=16&&_id<32){
            switch(this->_type){
            case che:
                return "車";
            case ma:
                return "馬";
            case pao:
                return "炮";
            case bing:
                return "卒";
            case jiang:
                return "將";
            case xiang:
                return "象";
            case shi:
                return "士";
            }
        }return "错误";
    }
};




#endif // STONE_H
